'use strict';

const Service = require('egg').Service;

class CustomerService extends Service {
  async saveCustomer(userinfo) {
      const existCustomer = await this.app.mysql.get('customer',{openId:userinfo.openId});
      if(!existCustomer){
          try{
            const result = await this.app.mysql.insert('customer',{
                openId:userinfo.openId,
                nickName:userinfo.nickName,
                avatar:userinfo.avatarUrl
            });
            if (result.affectedRows === 1){
                return true;
            }else{
                return false;
            }
            
          }catch(err){
              return false;
          }

      }
      return true;
  }
}

module.exports = CustomerService;
